<?php /* Smarty version Smarty3-RC3, created on 2013-10-11 07:33:01
         compiled from ".\templates\bhatthiCreditEntry.tpl" */ ?>
<?php /*%%SmartyHeaderCode:202555257a9ad2c8e15-98038516%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    'a5366f7279083ab5ca0fe6b41d24badd5b9e8cb3' => 
    array (
      0 => '.\\templates\\bhatthiCreditEntry.tpl',
      1 => 1381476492,
    ),
  ),
  'nocache_hash' => '202555257a9ad2c8e15-98038516',
  'function' => 
  array (
  ),
  'has_nocache_code' => false,
)); /*/%%SmartyHeaderCode%%*/?>
<?php if (!is_callable('smarty_function_html_options')) include 'D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sil1\include\Smarty\libs\plugins\function.html_options.php';
if (!is_callable('smarty_function_html_select_date')) include 'D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sil1\include\Smarty\libs\plugins\function.html_select_date.php';
?><?php $_template = new Smarty_Internal_Template("header.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
 echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript">
rowNumber = 1;
$(document).ready(function()
{
  $(".delete").live('click', function(event) 
  {
    $(this).parent().remove();
    setFine(this);
    totFineFunc(this);
    setAmount(this);
    totAmount(this);
  });
  $(".grossWeight").live('change',function(){
    setWeight($(this));
  });
  $(".weightPerc").live('change',function(){
    setWeight($(this).prev());
  });
  getOldAmount();
});

function addNewRow()
{
  $('#bhatthi tr:last').after('<tr class="bhitthiRow"><td><input type="checkbox" name="rojmelEntry['+rowNumber+']" value = "1" /></td><td><input type="text" name="particulars[]" \/><\/td><td><input type="text" name="grossWeight[]" class="grossWeight"  size="13"/><input type="text" name="weightPerc[]" class="weightPerc" value="<?php echo $_smarty_tpl->getVariable('weightPerc')->value;?>
"  size="3"/><input type="text" name="weight[]" class="weight" onChange="setFine(this)"  size="13"\/><\/td><td><input type="text" name="touch[]" class="touch" onChange="setFine(this)"\/><\/td><td><input type="text" name="fine[]" class="fine"  onChange="totFine()"\/><\/td><td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)"\/><\/td><td><input type="text" name="rate[]" class="rate" onChange="setAmount(this)"\/><\/td><td><input type="text" name="amount[]" class="amount"  onChange="totAmount()"\/><\/td><td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
<\/a><\/td><td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
<\/td><\/tr>');
  rowNumber++;
}

function setFine(txtObj)
{
  var row = $(txtObj).parents('.bhitthiRow');
  var price = (parseFloat(row.find('.weight').val().replace("$","")) * parseFloat(row.find('.touch').val())/100);
  isNaN(price) ? row.find('.fine').val("") : row.find('.fine').val(price);
  totFine();
}
function totFine()
{
  var totalFine = 0;
  var prevFineWithoutThisBill = 0;
  $('.fine').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totalFine += Number(price);
  });
  $('#totalFine').val(totalFine);
  //prevFineWithoutThisBill = $("#prevFineWithoutThisBill").val();
  $('#partyFine').val(parseFloat(prevPartyFine) - parseFloat(totalFine));
}
// Add  Fine InTo Previous Fine :Start 
function totFineFunc()
{
  var totFine = 0;
  
  $('.fine').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totFine += Number(price);
  });
  
  $('#totFine').val(totFine);
  prevFineWithoutThisBill = $("#prevFineWithoutThisBill").val();
  $('#partyFineEdit').val(parseFloat(prevFineWithoutThisBill) - parseFloat(totalFine));
}
// Add  Fine InTo Previous Fine :End
function setWeight(grossWeight)
{
  valuesAvailable = 100;
  grossWeightVal = grossWeight.val();
  percentageVal  = grossWeight.next().val();
  grossWeightObj = grossWeight.next().next();
  grossWeightObj.val(((grossWeightVal * percentageVal) / valuesAvailable) + parseFloat(grossWeightVal));
}

// Add  Fine InTo Amount Fine :Start 

function setAmount(txtObj)
{
  var row = $(txtObj).parents('.bhitthiRow');
  var price = parseFloat(row.find('.qty').val().replace("$","")) * parseFloat(row.find('.rate').val());
  isNaN(price) ? row.find('.amount').val("") : row.find('.amount').val(price);
  totAmount();
  setTotAmount();
}
function setTotAmount()
{
  var totQty    = 0;
  var totLabour = 0;
  var totAmount = 0;
  
  $('.amount').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totAmount += Number(price);
  });
  $('#totAmount').val(totAmount);
  $('#partyAmount').val(parseFloat(prevPartyAmount) -  parseFloat(totAmount));
}

// Add  Fine InTo Amount Fine :End
function totAmount()
{
  var totAmount = 0;
  var totalQty  = 0;
  
  $('.amount').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totAmount += Number(price);
  });
  
  $('.qty').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totalQty += Number(price);
  });
  
  $('#totalQty').val(totalQty);
  $('#partyAmountEdit').val(totAmount);
}
function getOldAmount()
  {
	  if(document.form1.party.value > 0)
	  {
        $.ajax({
	      type:"POST",
	      url:'getOldAmountBhatthi.php',
	      data:
	      {
	        partyId : document.form1.party.value
	      },
	      success: function(response)
	      {
	      	var temp = response.split(",");
	      	prevPartyFine = temp[0];
	      	prevPartyAmount = temp[1];
	      	$('#partyFine').val(prevPartyFine);
	      	$('#partyAmount').val(prevPartyAmount);
	      }
      });
	  }
  }
</script>
<form name="form1" action="" method="post">
<input type="hidden" name="bhatthiId" value="<?php echo $_smarty_tpl->getVariable('bhatthiId')->value;?>
" />
<input type="hidden" name="prevFineWithoutThisBill" id="prevFineWithoutThisBill" value="<?php echo $_smarty_tpl->getVariable('prevFineWithoutThisBill')->value;?>
" />
<input type="hidden" name="prevAmountWithoutThisBill" id="prevAmountWithoutThisBill" value="<?php echo $_smarty_tpl->getVariable('prevAmountWithoutThisBill')->value;?>
" />
<center><h4><?php echo $_smarty_tpl->getVariable('l_bhatthiCredit')->value;?>
</h4></center>
<div class="contentDiv">
  <table border="0" id="bhatthi" align="center" width="100%">
  <tr>
    <td colspan="4" class="table1">
      <?php echo $_smarty_tpl->getVariable('l_partySelect')->value;?>
 :
      <select name="party"  onChange="getOldAmount();">
        <?php echo smarty_function_html_options(array('values'=>$_smarty_tpl->getVariable('party')->value['id'],'output'=>$_smarty_tpl->getVariable('party')->value['name'],'selected'=>($_smarty_tpl->getVariable('bhatthiParty')->value)),$_smarty_tpl->smarty,$_smarty_tpl);?>

      </select>
    </td>
    <td colspan="5" class="table1">
      <?php echo $_smarty_tpl->getVariable('l_date')->value;?>
 : 
      <?php echo smarty_function_html_select_date(array('prefix'=>"curDate",'start_year'=>"-2",'end_year'=>"+1",'field_order'=>"DMY",'day_value_format'=>"%02d",'time'=>$_smarty_tpl->getVariable('bhatthiDate')->value),$_smarty_tpl->smarty,$_smarty_tpl);?>

    </td>
  </tr>
  <tr class="table1">
  	<th>&nbsp;</th>
    <th><?php echo $_smarty_tpl->getVariable('l_particulars')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_grossWeight')->value;?>
&nbsp;&nbsp;&nbsp;&nbsp<?php echo $_smarty_tpl->getVariable('l_weightPerc')->value;?>
;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_smarty_tpl->getVariable('l_weight')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_touch')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_fine')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_qty')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_rate')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_amount')->value;?>
</th>
    
  </tr>
  <?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['name'] = "sec";
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'] = is_array($_loop=count($_smarty_tpl->getVariable('bhatthi')->value)) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show'] = true;
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'] = 1;
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['start'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'] > 0 ? 0 : $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop']-1;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show']) {
    $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'];
    if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] == 0)
        $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show'] = false;
} else
    $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] = 0;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show']):

            for ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] = 1;
                 $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'];
                 $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration']++):
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['first']      = ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] == 1);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['last']       = ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total']);
?>
  <tr class="bhitthiRow">
  	<?php if ($_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['rojmelId']!=0){?>
    <td><input type="checkbox" name="rojmelEntry[<?php echo $_smarty_tpl->getVariable('smarty')->value['section']['sec']['index'];?>
]" value= "1" checked /></td>
    <?php }else{ ?>
    <td><input type="checkbox" name="rojmelEntry[<?php echo $_smarty_tpl->getVariable('smarty')->value['section']['sec']['index'];?>
]" value= "1" /></td>
    <?php }?>
    <td><input type="text" name="particulars[]" value="<?php echo $_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['particulars'];?>
" /></td>
    <td><input type="text" name="grossWeight[]" class="grossWeight" size="13"/>
    	  <input type="text" name="weightPerc[]" class="weightPerc" value="<?php echo $_smarty_tpl->getVariable('weightPerc')->value;?>
" size="3" />
    	  <input type="text" name="weight[]" class="weight" onChange="setFine(this)" value="<?php echo $_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['weight'];?>
" size="13" /></td>
    <td><input type="text" name="touch[]" class="touch" onChange="setFine(this)" value="<?php echo $_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['touch'];?>
" /></td>
    <td><input type="text" name="fine[]" class="fine" onChange="totFineFunc()" value="<?php echo $_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['fine'];?>
" /></td>
    <td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)" value="<?php echo $_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['qty'];?>
" /></td>
    <td><input type="text" name="rate[]" class="rate" onChange="setAmount(this)" value="<?php echo $_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['rate'];?>
" /></td>
    <td><input type="text" name="amount[]" class="amount" value="<?php echo $_smarty_tpl->getVariable('bhatthi')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['amount'];?>
" /></td>
    <td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
</a></td>
    <td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
</td>
    <td>&nbsp;</td>
  </tr>
  <?php endfor; endif; ?>
  <tr class="bhitthiRow">
    <td><input type="checkbox" name="rojmelEntry[]" value= "1" /></td>
    <td><input type="text" name="particulars[]" /></td>
    <td><input type="text" name="grossWeight[]" class="grossWeight"  size="13"/><input type="text" name="weightPerc[]" class="weightPerc" value="<?php echo $_smarty_tpl->getVariable('weightPerc')->value;?>
"  size="3"/><input type="text" name="weight[]" class="weight" onChange="setFine(this)"  size="13"/></td>
    <td><input type="text" name="touch[]"  class="touch"  onChange="setFine(this)"/></td>
    <td><input type="text" name="fine[]"   class="fine"   onChange="totFine()" /></td>
    <td><input type="text" name="qty[]"    class="qty"    onChange="setAmount(this)"/></td>
    <td><input type="text" name="rate[]"   class="rate"   onChange="setAmount(this)"/></td>
    <td><input type="text" name="amount[]" class="amount" onChange="totAmount()"  onChange="setTotAmount()"/></td>
    <td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
</a></td>
    <td>&nbsp;</td>
  </tr>
  </table>
  <table border="0" width="100%">
    <tr class="itemRowTot">
      <th width="150px;"><?php echo $_smarty_tpl->getVariable('l_total')->value;?>
</th>
      <th align="right" width="150px;">&nbsp;</th>
      <th align="right" width="150px;">&nbsp;</th>
      <th align="right"><input type="text" name="totalFine"   id="totalFine"   onChange="totFine()"/></th>
      <th align="right"><input type="text" name="totalQty"    id="totalQty"    onChange="totAmount()"/></th>
      <th align="right" width="150px;">&nbsp;</th>
      <th align="right"><input type="text" name="totalAmount" id="partyAmountEdit" onChange="totAmount()"/></th>
      <th colspan="2" width="100px;">&nbsp;</th>
    </tr>
  </table>
    <?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
    <div id="oldTotal" style="float:right;">
  	  <b>Prev. Fine</b> <input type="text" name="partyFine" id="partyFine" />
  	  <b>Prev. Amount</b> <input type='text' name='partyAmount' id='partyAmount' />
    </div>
  	<?php }else{ ?>
    <div id="oldTotal" style="float:right;">
    	<b>Prev. Fine</b> <input type="text" name="partyFine" id="partyFine" />
  	  <b>Prev. Amount</b> <input type='text' name='partyAmount' id='partyAmount' />
    </div>
  	<?php }?>
  <input type="submit" name="bhatthiAddBtn" value="<?php if (count($_smarty_tpl->getVariable('bhatthi')->value)>0){?><?php echo $_smarty_tpl->getVariable('l_save')->value;?>
<?php }else{ ?><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
<?php }?>"/>
</div>
</form>
<script type="text/javascript">
<?php if (count($_smarty_tpl->getVariable('bhatthi')->value)>0){?>
  totAmount();
  totFine();
  totFineFunc();
  setTotAmount();
<?php }?>
</script>
<?php $_template = new Smarty_Internal_Template("footer.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
 echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?>